package com.ykt.controller;

import com.jfinal.aop.Before;
import com.ykt.common.utils.UB;
import com.ykt.model.Service;
import com.ykt.service.AfterSalesService;
import com.ykt.validator.CommonValidator;
import com.ykt.vo.ResultVo;
import com.ykt.vo.ServiceVo;

import java.util.Date;
import java.util.List;

/**
 * 售后
 * @author long.hua
 * @version 1.0.0
 * @since 2016-04-17 18:38
 */
public class AfterSalesController extends BaseController {


    private AfterSalesService afterSalesService = enhance(AfterSalesService.class.getName(), AfterSalesService.class);

    public void create(){
        int userId = getParaToInt("userId");
        int orderId = getParaToInt("orderId");
        String serviceType = getPara("serviceType");
        String summary = getPara("summary");
        String reasons = getPara("reasons");
        String pic = getPara("pic");

        Service service = new Service();
        service.set(Service.user_id, userId);
        service.set(Service.order_id, orderId);
        service.set(Service.service_type, serviceType);
        service.set(Service.summary, summary);
        service.set(Service.reasons, reasons);
        service.set(Service.pic, pic);
        //service.set(Service.status, "NO");//状态：换货HAS_EXCHANGE 退货退款HAS_BACK 拒绝HAS_REFUSE
        service.set(Service.created_time, new Date());

        int id = afterSalesService.save(service);

        this.returnJson(ResultVo.success(id));
    }


    /**
     * 根据订单ID查询对应的售后
     */
    @Before({CommonValidator.OrderIdValidator.class})
    public void find() {
        int orderId = UB.i(getPara("orderId"));

        List<ServiceVo> serviceVos = afterSalesService.findByOrderId(orderId);

        this.returnJson(ResultVo.success(serviceVos));
    }

}
